package com.psychology.vo;

import lombok.Data;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

@Data
public class ScheduleVO {
    private Long id;
    private String date; // 日期，格式：YYYY-MM-DD
    private String timeSlot; // 时间段，格式：HH:mm-HH:mm
    private String type; // 咨询类型：online/offline
    private String status; // 状态：available/booked/cancelled
    private String statusText; // 状态文本：可预约/已预约/已取消
    private ClientInfoVO client; // 如果已预约，则包含客户信息

    public static ScheduleVO fromEntity(Schedule schedule) {
        ScheduleVO vo = new ScheduleVO();
        vo.setId(schedule.getId());
        vo.setDate(schedule.getDate().format(DateTimeFormatter.ISO_LOCAL_DATE));
        vo.setTimeSlot(schedule.getTimeSlot());
        vo.setType(schedule.getType());
        vo.setStatus(schedule.getStatus());
        vo.setStatusText(getStatusText(schedule.getStatus()));

        // 如果已预约，设置客户信息
        if ("booked".equals(schedule.getStatus()) && schedule.getAppointment() != null) {
            vo.setClient(ClientInfoVO.fromAppointment(schedule.getAppointment()));
        }

        return vo;
    }

    private static String getStatusText(String status) {
        switch (status) {
            case "available":
                return "可预约";
            case "booked":
                return "已预约";
            case "cancelled":
                return "已取消";
            default:
                return "未知状态";
        }
    }
}